package utils

import "strconv"

func StrToInt(v string) int {
	i, err := strconv.Atoi(v)
	if err != nil {
		return 0
	}
	return i
}
func StrToInt64(v string) int64 {
	i, err := strconv.ParseInt(v, 10, 64)
	if err != nil {
		return 0
	}
	return i
}
func IntToStr(i int) string {
	return strconv.Itoa(i)
}

func ToStr(v interface{}) string {
	switch v.(type) {
	case string:
		return v.(string)
	case int:
		return strconv.Itoa(v.(int))
	case int64:
		return strconv.FormatInt(v.(int64), 10)
	case []byte:
		return string(v.([]byte))
	}
	result, err := v.(string)
	if err {
		return ""
	}
	return result
}

func ToInt(v interface{}) (result int) {
	switch v.(type) {
	case string:
		result, _ = strconv.Atoi(v.(string))
		return
	case int:
		return v.(int)
	case float64:
		return int(v.(float64))
	case int64:
		return int(v.(int64))
	}
	data, err := v.(string)
	if err {
		return 0
	}
	result, _ = strconv.Atoi(data)
	return
}
